package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanBoZhiWeiSavePO;
import com.ct.application.shipping.model.po.ChuanBoZhiWeiSearchPO;
import com.ct.application.shipping.model.vo.ChuanBoZhiWeiVO;
import com.ct.application.shipping.service.ChuanBoZhiWeiService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.*;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import com.ct.utils.jwt.UserInfo;
import com.ct.utils.threadlocal.UserThreadLocal;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 船舶职位配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船舶职位",path="/api/v1/chuanbozhiwei",code = "G1000",sorted = 6)
public class ChuanBoZhiweiController extends BaseController {

    @Resource
    private ChuanBoZhiWeiService chuanBoZhiWeiService;


    /**
     * 查询船舶职位列表
     * @return
     */
    @PostMapping("/chuanbozhiwei/listbiao")
    @HasPermissionApi
    @PermissionApi(title = "查询船舶职位列表2",path="/api/v1/chuanbozhiwei/listbiao",code = "G1007",sorted = 7)
    public List<ChuanBoZhiWeiVO> findChuanBoZhiWeisBiao() {
        return chuanBoZhiWeiService.findChuanBoZhiWeisBiao();
    }


    /**
     * 查询船舶职位列表
     * @return
     */
    @PostMapping("/chuanbozhiwei/listbiao2")
    @HasPermissionApi
    @LoginIgnore
    @PermissionApi(title = "查询船舶职位列表2",path="/api/v1/chuanbozhiwei/listbiao",code = "G10072",sorted = 77)
    public List<ChuanBoZhiWeiVO> findChuanBoZhiWeisBiao2(@RequestParam("sid")Long sid) {
        if(Objects.nonNull(sid)) {
            UserInfo userInfo = new UserInfo();
            userInfo.setSystemId(sid);
            UserThreadLocal.set(userInfo);
        }
        return chuanBoZhiWeiService.findChuanBoZhiWeisBiao();
    }


    /**
     * 查询船舶职位列表
     * @param chuanBoZhiWeiSearchPO
     * @return
     */
    @PostMapping("/chuanbozhiwei/list")
    @PermissionApi(title = "查询船舶职位列表",path="/api/v1/chuanbozhiwei/list",code = "G1001",sorted = 1)
    public Page<ChuanBoZhiWeiVO> findChuanBoZhiWeis(@Validated @RequestBody ChuanBoZhiWeiSearchPO chuanBoZhiWeiSearchPO) {
        return chuanBoZhiWeiService.findChuanBoZhiWei(chuanBoZhiWeiSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanbozhiwei/saveupdate")
    @ApiLog("船舶职位保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船舶职位保存和更新",path="/api/v1/chuanbozhiwei/saveupdate",code = "G1003",sorted = 3)
    public Boolean saveUpdateChuanBoZhiWei(@Validated @RequestBody ChuanBoZhiWeiSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanBoZhiWeiService.updateChuanBoZhiWei(savePO);
        }else {
            return chuanBoZhiWeiService.saveChuanBoZhiWei(savePO);
        }
    }

    /**
     * 根据id查询船舶职位
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanbozhiwei/get/{id}")
    @PermissionApi(title = "根据id查询船舶职位",path="/api/v1/chuanbozhiwei/get/{id}",code = "G1004",sorted = 4)
    public ChuanBoZhiWeiVO getChuanBoZhiWeiById(@PathVariable("id") Long id) {
        return chuanBoZhiWeiService.getChuanBoZhiWei(id);
    }


    /**
     * 根据id删除船舶职位
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanbozhiwei/del/{id}")
    @ApiLog("根据id删除船舶职位")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船舶职位",path="/api/v1/chuanbozhiwei/del/{id}",code = "G1005",sorted = 5)
    public Boolean delChuanBoZhiWeiById(@PathVariable("id") Long id) {
        return chuanBoZhiWeiService.delChuanBoZhiWei(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanbozhiwei/update/status")
    @ApiLog("船舶职位修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船舶职位修改状态",path="/api/v1/chuanbozhiwei/update/status",code = "G1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanBoZhiWeiService.updateStatus(statusRequest);
    }
}
